<include file="Public/header"/>
<body class="body-bg">
<div class="park-header" style="z-index: 103;">
    <div class="park-header__title">
        <span id="category-title">{$now_category['name']}</span>&nbsp;<i class="iconfont icon-xia"></i>
    </div>
    <div class="park-header__left" onclick="window.location='/Home/Category/index/';">
        <i class="iconfont icon-fanhui"></i>
    </div>
    <div class="park-header__right" onclick="window.location='/Home/Index/search/';">
        <i class="iconfont icon-search"></i>
    </div>
</div>
<div class="park-sortNav-tabs">
    <ul id="nav_type">
        <li data-id="1" <if condition="$type_id eq 1">class="active"</if>>默认</li>
        <li data-id="2" <if condition="$type_id eq 2">class="active"</if>>最新</li>
        <li data-id="3" <if condition="$type_id eq 3">class="active"</if>>销量</li>
        <li data-id="4" data-type="{$desc}" class="price <if condition='$type_id eq 4'>active</if>">
            价格
            <span>
                <i class="iconfont icon-shangjiantou"></i>
                <i class="iconfont icon-xiajiantou"></i>
            </span>
        </li>
    </ul>
</div>
<div class="container" style="margin-left: 1.75rem;">
    <div class="park__goods">
        <ul id="goods_list"></ul>
    </div>
</div>
<div class="park-fixed-cart" onclick="window.location='/Home/Cart/index/';">
    <i class="iconfont icon-cart"></i>
    <if condition="$cart_number gt 0">
        <span class="num" id="cart_number">{$cart_number}</span>
    </if>
</div>
<div class="park-mask"></div>
<div id="category-list" class="park-category-fixed">
    <ul>
        <volist name="one_cate" id="val">
        <li data-title="{$val.name}" data-id="{$val.id}" <if condition="$val['id'] eq $now_category['id']">class="active"</if>>
            <i class="iconfont icon-gou"></i>{$val.name}
        </li>
        </volist>
    </ul>
</div>
<div class="park-category2-fixed">
    <ul>
        <volist name="two_cate" id="val">
             <li data-id="{$val.id}" class="li <if condition='$sid eq $val[id]'>active</if>">{$val.name}</li>
        </volist>
    </ul>
</div>
<script src="__ROOT__/Public/Home/layer/layer.js"></script>
<script>
    var options = {
        type: 'get', // default 'get'
        dataType: 'html' // default 'json'
    };
    $(function () {
        var url = '/Home/Category/ajaxGoodsList/';
        var sid = '{$sid}';
        var type_id = '{$type_id}';
        var desc = '{$desc}';
        var params = {'sid':sid,'type_id':type_id,'desc':desc};
        PARK.dropLoad(PARK.dropAjax(options, url, params, function (data) {
            var data = JSON.parse(data);
            var html = '';
            for (var i = 0; i < data.result.length; i++) {
                var saleout = '';
				html += '<li>';
				if(data['result'][i]['is_sold']==1){
					saleout = 'saleout';
				}
                html += '    <div onclick="goods_detail(' + data['result'][i]['goods_id'] + ',' + data['result'][i]['store_id'] + ');" class="park-goods__pic '+saleout+'" style="background-image: url(' + data['result'][i]['thumb'] + ')"></div>';
                html += '    <div onclick="goods_detail(' + data['result'][i]['goods_id'] + ',' + data['result'][i]['store_id'] + ');" class="park-goods__info">';
                html += '        <p class="name">' + data['result'][i]['goods_name'] + '</p>';
                html += '        <p class="desc">' + data['result'][i]['store_name'] + ' 提供</p>';
                html += '        <p class="spec">' + data['result'][i]['spec_name'] + '&nbsp;</p>';
                html += '        <p class="price-line">';
                html += '            <span class="price">￥<em>' + data['result'][i]['left_price'] + '</em>' + data['result'][i]['right_price'] + '</span>';
                html += '        </p>';
                html += '    </div>';
                html += '    <div class="park-goods__pos">';
                html += '        <div class="cart" onclick="sum_form('+data['result'][i]['goods_id']+','+data['result'][i]['store_id']+','+data['result'][i]['spec_id']+');">';
                html += '            <i class="iconfont icon-cart"></i>';
                html += '        </div>';
                html += '    </div>';
                html += '</li>';
            }
            $('#goods_list').append(html);
            if(data.is_page==1){
                PARK.unDropLoad();
            }
        }));
        var Category = {
            hideList: function () {
                $('#category-list').hide();
            },
            handleEvents: function () {
                var _this = this;
                // 点击标题
                $(document).on('click', '#category-title', function () {
                    $('#category-list').toggle();
                    PARK.toggleMask();
                });

                // 选择类型
                $(document).on('click', '#category-list li', function () {
                    var id = $(this).attr('data-id');
                    window.location='/Home/Category/goods_list/cat_id/'+id;
                });

                // 点击遮罩隐藏
                $(document).on('click', '.park-mask', function () {
                    _this.hideList();
                });

                // 点击二级分类
                $(document).on('click', '.park-category2-fixed .li', function () {
                    $('.park-category2-fixed .li').removeClass('active');
                    $(this).addClass('active');
                    var id = $(this).attr('data-id');
                    window.location='/Home/Category/goods_list/cat_id/'+'{$cat_id}'+'/sid/'+id;
                });
                $(document).on('click', '#nav_type li', function () {
                    $(this).addClass('active').siblings().removeClass('active');
                    var id = $(this).attr('data-id');
                    if(id==4){
                        var desc = $(this).attr('data-type');
                        if(desc=='asc'){
                            desc = 'desc';
                        }else{
                            desc = 'asc';
                        }
                        var url = '/Home/Category/goods_list/cat_id/'+'{$cat_id}'+'/sid/'+'{$sid}'+'/type_id/'+id+'/desc/'+desc;
                    }else{
                        var url = '/Home/Category/goods_list/cat_id/'+'{$cat_id}'+'/sid/'+'{$sid}'+'/type_id/'+id;
                    }
                    window.location = url;
                });
            },
            init: function () {
                this.handleEvents();
            }
        };

        Category.init();
    });
    function goods_detail(id,store_id){
        window.location = "{:U('Home/Index/detail',"",false)}/id/"+id+'/store_id/'+store_id;
    }
    function sum_form(goods_id,store_id,spec_id){
        if(!spec_id){
            return false;
        }
        var goods_number = 1;
        $.post('/Home/Cart/add_cart/',{goods_id:goods_id,store_id:store_id,spec_id:spec_id,goods_number:goods_number},function(data){
            if(data.code==200){
                $('#cart_number').html(data.result);
            }
            layer.open({
                content:data.msg
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
        },'json');
    }
</script>
</body>
</html>